<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="UserID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入UserID" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="CustNo" prop="custNo">
        <el-input v-model="queryParams.custNo" placeholder="请输入CustNo" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="BVN" prop="bvnAccount">
        <el-input v-model="queryParams.bvnAccount" placeholder="请输入BVN" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="AccountNumber" prop="accountNumber">
        <el-input v-model="queryParams.accountNumber" placeholder="请输入AccountNumber" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="FirstName" prop="firstName">
        <el-input v-model="queryParams.firstName" placeholder="请输入FirstName" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="MiddleName" prop="middleName">
        <el-input v-model="queryParams.middleName" placeholder="请输入MiddleName" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="LastName" prop="lastName">
        <el-input v-model="queryParams.lastName" placeholder="请输入LastName" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="Birthday" prop="birthDate">
        <el-input v-model="queryParams.birthDate" placeholder="请输入Birthday" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="Age" prop="age">
        <el-input v-model="queryParams.age" placeholder="请输入Age" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="Gender" prop="gender">
        <el-input v-model="queryParams.gender" placeholder="请输入Gender" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="BankCode" prop="bankCode">
        <el-input v-model="queryParams.bankCode" placeholder="请输入银行编码" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="PhoneNumber" prop="phoneNumber">
        <el-input v-model="queryParams.phoneNumber" placeholder="请输入PhoneNumber" clearable size="small"
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="State" prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择State" clearable size="small">
          <el-option v-for="dict in stateOptions" :key="dict.dictValue" :label="dict.dictLabel"
                     :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="KycRoute" prop="exqApi">
        <el-input v-model="queryParams.exqApi" placeholder="请输入kyc 路由" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="Fingerprint" prop="fingerprint">
        <el-input v-model="queryParams.fingerprint" placeholder="请输入fingerprint" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" style="margin-left: 37px;">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['bizsys:realname_auth_log:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                   v-hasPermi="['bizsys:realname_auth_log:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                   @click="handleDelete" v-hasPermi="['bizsys:realname_auth_log:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['bizsys:realname_auth_log:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="realname_auth_logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" width="100" prop="id" />
      <el-table-column label="UserID" align="center" width="300" prop="userId" />
      <el-table-column label="CustNo" align="center" width="200" prop="custNo" />
      <el-table-column label="FirstName" align="center" width="120" prop="firstName" />
      <el-table-column label="MiddleName" align="center" width="120" prop="middleName" />
      <el-table-column label="LastName" align="center" width="120" prop="lastName" />
      <el-table-column label="Birthday" align="center" width="120" prop="birthDate" />
      <el-table-column label="Age" align="center" width="100" prop="age" />
      <el-table-column label="Gender" align="center" width="100" prop="gender" />
      <el-table-column label="BVN" align="center" width="120" prop="bvnAccount" />
      <el-table-column label="AccountNumber" align="center" width="120" prop="accountNumber" />
      <el-table-column label="BankCode" align="center" width="250" prop="bankCode" />
      <el-table-column label="PhoneNumber" align="center" width="150" prop="phoneNumber" />
      <el-table-column label="KycRoute" align="center" width="400" prop="exqApi" />
      <el-table-column label="ErrorMsg" align="center" width="400" prop="errorMsg" />
      <el-table-column label="Fingerprint" align="center" width="300" prop="fingerprint" />
      <el-table-column label="State" align="center" width="100" prop="state" :formatter="stateFormat" />
      <el-table-column label="Remark" align="center" width="120" prop="remark" />
      <el-table-column label="CreateTime" align="center" width="180" prop="createTime">
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="Operation" align="center" width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['bizsys:realname_auth_log:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['bizsys:realname_auth_log:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!-- 添加或修改实名认证日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="UserID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入UserID" />
        </el-form-item>
        <el-form-item label="CustNo" prop="custNo">
          <el-input v-model="form.custNo" placeholder="请输入CustNo" />
        </el-form-item>
        <el-form-item label="FirstName" prop="firstName">
          <el-input v-model="form.firstName" placeholder="请输入FirstName" />
        </el-form-item>
        <el-form-item label="MiddleName" prop="middleName">
          <el-input v-model="form.middleName" placeholder="请输入MiddleName" />
        </el-form-item>
        <el-form-item label="LastName" prop="lastName">
          <el-input v-model="form.lastName" placeholder="请输入LastName" />
        </el-form-item>
        <el-form-item label="Birthday" prop="birthDate">
          <el-input v-model="form.birthDate" placeholder="请输入Birthday" />
        </el-form-item>
        <el-form-item label="Age" prop="age">
          <el-input v-model="form.age" placeholder="请输入Age" />
        </el-form-item>
        <el-form-item label="Gender" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入Gender" />
        </el-form-item>
        <el-form-item label="BVN" prop="bvnAccount">
          <el-input v-model="form.bvnAccount" placeholder="请输入BVN" />
        </el-form-item>
        <el-form-item label="AccountNumber" prop="accountNumber">
          <el-input v-model="form.accountNumber" placeholder="请输入AccountNumber" />
        </el-form-item>
        <el-form-item label="BankCode" prop="bankCode">
          <el-input v-model="form.bankCode" placeholder="请输入银行编码" />
        </el-form-item>
        <el-form-item label="PhoneNumber" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入PhoneNumber" />
        </el-form-item>
        <el-form-item label="State" prop="state">
          <el-select v-model="form.state" placeholder="请选择State">
            <el-option v-for="dict in stateOptions" :key="dict.dictValue" :label="dict.dictLabel"
                       :value="dict.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="KycRoute" prop="exqApi">
          <el-input v-model="form.exqApi" placeholder="请输入kyc 路由" />
        </el-form-item>
        <el-form-item label="Fingerprint" prop="fingerprint">
          <el-input v-model="form.fingerprint" placeholder="请输入fingerprint" />
        </el-form-item>
        <el-form-item label="ErrorMsg" prop="errorMsg">
          <el-input v-model="form.errorMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="Remark" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入Remark" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRealname_auth_log,
  getRealname_auth_log,
  delRealname_auth_log,
  addRealname_auth_log,
  updateRealname_auth_log,
  exportRealname_auth_log
} from "@/api/bizsys/realname_auth_log";

export default {
  name: "Realname_auth_log",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实名认证日志表格数据
      realname_auth_logList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // State字典
      stateOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bankCode: null,
        userId: null,
        custNo: null,
        firstName: null,
        middleName: null,
        lastName: null,
        birthDate: null,
        age: null,
        gender: null,
        bvnAccount: null,
        accountNumber: null,
        phoneNumber: null,
        state: null,
        errorMsg: null,
        exqApi: null,
        fingerprint: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [{
          required: true,
          message: "UserID不能为空",
          trigger: "blur"
        }],
        firstName: [{
          required: true,
          message: "FirstName不能为空",
          trigger: "blur"
        }],
        lastName: [{
          required: true,
          message: "LastName不能为空",
          trigger: "blur"
        }],
        birthDate: [{
          required: true,
          message: "Birthday不能为空",
          trigger: "blur"
        }],
        accountNumber: [{
          required: true,
          message: "AccountNumber不能为空",
          trigger: "blur"
        }],
        phoneNumber: [{
          required: true,
          message: "PhoneNumber不能为空",
          trigger: "blur"
        }],
        createTime: [{
          required: true,
          message: "创建时间不能为空",
          trigger: "blur"
        }],
        updateTime: [{
          required: true,
          message: "更新时间不能为空",
          trigger: "blur"
        }]
      }
    };
  },
  created() {
    // this.getList();
    this.getDicts("state").then(response => {
      this.stateOptions = response.data;
    });
  },
  methods: {
    /** 查询实名认证日志列表 */
    getList() {
      this.loading = true;
      listRealname_auth_log(this.queryParams).then(response => {
        this.realname_auth_logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // State字典翻译
    stateFormat(row, column) {
      return this.selectDictLabel(this.stateOptions, row.state);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bankCode: null,
        id: null,
        userId: null,
        custNo: null,
        firstName: null,
        middleName: null,
        lastName: null,
        birthDate: null,
        age: null,
        gender: null,
        bvnAccount: null,
        accountNumber: null,
        phoneNumber: null,
        state: null,
        errorMsg: null,
        exqApi: null,
        remark: null,
        fingerprint: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加实名认证日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRealname_auth_log(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改实名认证日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRealname_auth_log(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRealname_auth_log(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除实名认证日志编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delRealname_auth_log(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有实名认证日志数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportRealname_auth_log(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
